﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity = SoTaiChinh.Library.Entity;
using Business = SoTaiChinh.Library.Business;
public partial class templates_client_usercontrols_structure : System.Web.UI.UserControl
{
    Entity.PhongBan clsE_PhongBan = new SoTaiChinh.Library.Entity.PhongBan();
    Business.PhongBan clsB_PhongBan = new SoTaiChinh.Library.Business.PhongBan();
    Entity.CanBo clsE_CanBo = new SoTaiChinh.Library.Entity.CanBo();
    Business.CanBo clsB_CanBo = new SoTaiChinh.Library.Business.CanBo();
    protected void Page_Load(object sender, EventArgs e)
    {

        //if (!IsPostBack)
        //{
        //    ChiTiet.Visible = false;
        //    rptPhongBan.DataSource = clsB_PhongBan.Select(clsE_PhongBan);
        //    rptPhongBan.DataBind(); 
        //}

        if (!IsPostBack)
        {
            string idphong = Request.QueryString["phongban"].ToString();
            if (idphong != "0")
            {
                DataTable dt = new DataTable();
                clsE_PhongBan.IdPhong=clsE_CanBo.IdPhong = Convert.ToInt32(idphong);
                dt = clsB_PhongBan.SelectPrimarykey(clsE_PhongBan);
                DataListNhanVien.DataSource = clsB_CanBo.SelectCanBoTheoPhongBan(clsE_CanBo);
                DataListNhanVien.DataBind();
                lbTieuDe.Text = dt.Rows[0]["TenPhong"].ToString();
                lbNhiemVuPhong.Text = dt.Rows[0]["NhiemVu"].ToString();
                setVisiblePhongBan(false);
            }
            else
            {
                lbTieuDe.Text = "Danh sách cán bộ sở tài chính";
                setVisiblePhongBan(false);
            }
        }

    }
    private void setVisiblePhongBan(bool set)
    {

        //if (e.CommandName == "xem")
        //{
        //    ChiTiet.Visible = false;
        //    danhsach.Visible = true;
        //    clsE_CanBo.IdPhong = Convert.ToInt32(e.CommandArgument.ToString());
        //    DataListNhanVien.DataSource= clsB_CanBo.SelectCanBoTheoPhongBan(clsE_CanBo);
        //    DataListNhanVien.DataBind();
        //}

        ChiTiet.Visible = set;
        danhsach.Visible = !set;
        nhiemvuphong.Visible = !set;

    }
    protected void DataListNhanVien_ItemCommand(object source, DataListCommandEventArgs e)
    {

        //if (e.CommandName == "XemChiTiet")
        //{
        //    ChiTiet.Visible = true;
        //    danhsach.Visible = false;
        //    clsE_CanBo.IdNV = Convert.ToInt32(e.CommandArgument.ToString());
        //    DataTable dt = clsB_CanBo.SelectPrimarykey(clsE_CanBo);
        //    HinhCanBo.ImageUrl = "~/uploads/hinhanhcanbo/" + dt.Rows[0]["HinhAnh"].ToString(); ;
        //    lbTen.Text = dt.Rows[0]["TenNV"].ToString();
        //    lbChuVu.Text = dt.Rows[0]["TenChucVu"].ToString();
        //    lbNgaySinh.Text = dt.Rows[0]["NgaySinh"].ToString();
        //    lbDiaChi.Text = dt.Rows[0]["DiaChi"].ToString();
        //    lbDienThoai.Text = dt.Rows[0]["SoDienThoai"].ToString();
        //    lbEmail.Text = dt.Rows[0]["Email"].ToString();
        //    lbHocVi.Text = dt.Rows[0]["TrinhDoChuyenMon"].ToString();
        //    lbNhiemVu.Text = dt.Rows[0]["MoTaNhiemVu"].ToString();            
        //}

        if (e.CommandName == "XemChiTiet")
        {
            setVisiblePhongBan(true);
            clsE_CanBo.IdNV = Convert.ToInt32(e.CommandArgument.ToString());
            DataTable dt = clsB_CanBo.SelectPrimarykey(clsE_CanBo);
            HinhAnhCanBo.ImageUrl = "~/uploads/hinhanhcanbo/" + dt.Rows[0]["HinhAnh"].ToString(); ;
            lbTen.Text = dt.Rows[0]["TenNV"].ToString();
            lbChucVu.Text = dt.Rows[0]["TenChucVu"].ToString();
            lbNgaySinh.Text = dt.Rows[0]["NgaySinh"].ToString();
            lbDiaChi.Text = dt.Rows[0]["DiaChi"].ToString();
            lbDienThoai.Text = dt.Rows[0]["SoDienThoai"].ToString();
            lbEmail.Text = dt.Rows[0]["Email"].ToString();
            lbTrinhDo.Text = dt.Rows[0]["TrinhDoChuyenMon"].ToString();
            lbNhiemVu.Text = dt.Rows[0]["MoTaNhiemVu"].ToString();            
        }

    }   
    protected void btnTroVe_Click(object sender, EventArgs e)
    {

        //ChiTiet.Visible = false;
        //danhsach.Visible = true;

        setVisiblePhongBan(false);

    }
}
